<template>
  <div class="app-container">
    <el-card>
      <el-row>
        <el-col :span="24">
          <div class="bra flex">
            <p>就餐类型：早餐</p> <p>订餐人数：{{ mealsObject.breakfastNumber ? mealsObject.breakfastNumber : 0}}</p>
            <p>取餐人数：{{ mealsObject.breakfastNumberTake ? mealsObject.breakfastNumberTake : 0}}</p>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="lun flex">
            <p>就餐类型：午餐</p><p>订餐人数：{{ mealsObject.lunchNumber ? mealsObject.lunchNumber : 0}}</p>
            <p>取餐人数：{{ mealsObject.lunchNumberTake ? mealsObject.lunchNumberTake : 0}}</p>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="din flex">
            <p>就餐类型：晚餐</p><p>订餐人数：{{ mealsObject.dinnerNumber ? mealsObject.dinnerNumber : 0}}</p>
            <p>取餐人数：{{ mealsObject.dinnerNumberTake ? mealsObject.dinnerNumberTake : 0}}</p>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <el-form style="margin-top: 40px" :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="用户" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入用户名称"
          clearable
          size="small"
          @input="handleQuery"
        />
      </el-form-item>
      <el-form-item label="取餐状态" prop="isTakeFood">
        <el-select v-model="queryParams.isTakeFood" placeholder="请选择取餐状态" clearable size="small" @change="handleQuery">
          <el-option label="已取" value="1" />
          <el-option label="未取" value="0" />
        </el-select>
      </el-form-item>

      <el-form-item label="所属公司" prop="companyId">
        <el-select v-model="queryParams.deptId" placeholder="请选择所属公司" clearable size="small" @change="handleQuery">
          <el-option v-for="item in companys" :key="item.id" :label="item.text" :value="item.id"></el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="就餐类型" prop="diningType">
        <el-select v-model="queryParams.diningType" placeholder="请选择就餐类型" clearable size="small" @change="handleQuery">
          <el-option label="早餐" value="1" />
          <el-option label="午餐" value="2" />
          <el-option label="晚餐" value="3" />
          <el-option label="接待餐" value="4" />
          <el-option label="其它" value="5" />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="总金额" prop="totalAmount">
        <el-input
          v-model="queryParams.totalAmount"
          placeholder="请输入总金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:order:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:order:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['system:order:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:order:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column fixed label="序号" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum-1)*queryParams.pageSize+(scope.$index + 1)}} </span>
        </template>
      </el-table-column>
     <!--  <el-table-column label="订单编号" align="center" prop="num" />
 -->
      <el-table-column label="订单编号" align="center" :show-overflow-tooltip="true">
         <template slot-scope="scope">
          <router-link :to="'/ordermanager/order/data/' + scope.row.id" class="link-type">
            <span>{{ scope.row.num }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="用户" align="center" prop="username" />
      <el-table-column label="取餐状态" align="center" prop="isTakeFood">
            <template slot-scope="scope">
                <span v-if="scope.row.isTakeFood == 0">未取</span>
                <span v-if="scope.row.isTakeFood == 1">已取</span>
            </template>
      </el-table-column>
      <el-table-column label="总金额 (元)" align="center" prop="totalAmount" />
      <el-table-column label="预定日期" align="center" prop="date" />
      <el-table-column label="就餐类型" align="center" prop="diningType" >
        <template slot-scope="scope">
          <span v-if="scope.row.diningType == 1">早餐</span>
          <span v-if="scope.row.diningType == 2">午餐</span>
          <span v-if="scope.row.diningType == 3">晚餐</span>
          <span v-if="scope.row.diningType == 4">接待餐</span>
          <span v-if="scope.row.diningType == 5">其它</span>
        </template>
      </el-table-column>

      <el-table-column label="所属公司" align="center" prop="companyName" />

 <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            :disabled="scope.row.isTakeFood == 1"
            v-hasPermi="['system:order:revise']"
          >取餐</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:order:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户Id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户Id" />
        </el-form-item>
        <el-form-item label="取餐状态" prop="diningType">
        <el-select v-model="form.isTakeFood" placeholder="请选择取餐状态" clearable size="small">
          <el-option label="未取" value="0" />
          <el-option label="已取" value="1" />
        </el-select>
      </el-form-item>
        <el-form-item label="总金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入总金额" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->

    <!-- 订餐记录详情信息 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="orderRecordForm" :rules="rules" label-width="80px">
        <el-form-item label="菜品ID" prop="foodId">
          <el-input v-model="orderRecordForm.foodId" placeholder="请输入菜品ID" />
        </el-form-item>
        <el-form-item label="订单ID" prop="orderId">
          <el-input v-model="orderRecordForm.orderId" placeholder="请输入订单ID" />
        </el-form-item>
        <el-form-item label="数量" prop="count">
          <el-input v-model="orderRecordForm.count" placeholder="请输入数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, takeId, delOrder, addOrder, updateOrder, exportOrder, getNumber } from "@/api/ordermanager/order";
import { getCompanys } from '@/api/system/dept';
import  moment from 'moment'

export default {
  name: "Order",
  data() {
    return {
      mealsObject: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      orderList: [],
      testvalue: 3,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        username: undefined,
        isTakeFood: undefined,
        totalAmount: undefined,
        date: moment(new Date()).format(`yyyy-MM-DD`),
        deptId:undefined,
      },
      // 表单参数
      form: {},
      // 公司信息
      companys: [],
      orderRecordForm: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getCompanyList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    addStarS(row){
        if(row.serviceEvaluation){
            return row.serviceEvaluation+"星"
        }else{
            return ""
        }

    },
    addStarF(row){
        if(row.foodEvaluation){
            return row.foodEvaluation+"星"
        }else{
            return ""
        }
    },
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
      getNumber({
        beginTime: moment(new Date(new Date(new Date().toLocaleDateString()).getTime())).format("YYYY-MM-DD HH:mm:ss"),
        endTime: moment(new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)).format("YYYY-MM-DD HH:mm:ss")
      }).then((data) => {
          this.mealsObject = data.data;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,
        isTakeFood: undefined,
        totalAmount: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.deptId=undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      this.$confirm('是否取餐?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        customClass:'del-model',
        type: 'warning'
      }).then(() => {
        takeId(id).then((data) => {
          this.getList();
          this.$message({
            type: 'success',
            message: '取餐成功!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消取餐'
        });
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateOrder(this.form).then(response => {
              if (response.code == 0) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addOrder(this.form).then(response => {
              if (response.code == 0) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportOrder(queryParams);
        }).then(response => {
          this.download(response.data);
        }).catch(function() {});
    },
    /** 获取公司信息 */
    getCompanyList() {
      getCompanys().then(response => {
        this.companys = response.data;
      });
    },
  }
};
</script>

<style scoped>
  .flex {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
  }
</style>
